package com.uab.ia.utils;

import android.content.Context;
import android.os.AsyncTask;

import com.android.dataframework.DataFramework;

public class AsyncTaskBBDD extends AsyncTask<Context, Void, Integer>{

	private OnBBDDChargedListener listener;
	
	@Override
	protected Integer doInBackground(Context... params) {
		
		try {
			DataFramework.getInstance().open(params[0], "com.uab.ia");
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
		
		return 0;
	}

	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		if (getListener() != null){
			if (result == 0) {
				getListener().onBBDChardedDone();
			}
			else if (result == -1) {
				getListener().onBBDChardedError();
			}
		}
		
	}
	
	public OnBBDDChargedListener getListener() {
		return listener;
	}

	public void setListener(OnBBDDChargedListener listener) {
		this.listener = listener;
	}

	public interface OnBBDDChargedListener {
		public void onBBDChardedDone();
		public void onBBDChardedError();
	}
}
